<?php require VIEW_ROOT.'/common/header.php'?>

<?php
$hour_data = array();
$hour_label = array();
foreach ($res_hour_top as $row) {
	$hour_data[$row['hour']] = $row['hits'];
}
$hour_data_final = array();
for($i = 0; $i < 33; $i++) {
	$hour_data_final[$i] = isset($hour_data[$i%24]) ? $hour_data[$i%24] : 0;
	$hour_label[] = $i%24;
}

include("resource/pchart/pData.class.php");   
include("resource/pchart/pChart.class.php");   

// (1)数据  
$DataSet = new pData();
$DataSet->AddPoint($hour_data_final, "Serie1");
//$DataSet->AddPoint($hour_data_final2, "Serie2");
$DataSet->AddPoint($hour_label, "Serie3");
$DataSet->AddSerie('Serie1');  
//$DataSet->AddSerie('Serie2');  
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("All Days","Serie1");   
//$DataSet->SetSerieName("Today","Serie2");   
$DataSet->SetYAxisName("Hits");
$DataSet->SetXAxisName("Hour");

// (2)图表
$Test = new pChart(700,255);
$Test->setFontProperties("resource/fonts/tahoma.ttf",8);   
$Test->setGraphArea(70,30,680,210); 
$Test->drawFilledRoundedRectangle(7,7,693,248,5,240,240,240);   
$Test->drawRoundedRectangle(5,5,695,250,5,230,230,230); 
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);   
$Test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line
$Test->setFontProperties("resource/fonts/tahoma.ttf",6);   
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the line graph
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());   
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

// (3)显示
$Test->setFontProperties("resource/fonts/tahoma.ttf",8);   
$Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255);   
$Test->setFontProperties("resource/fonts/tahoma.ttf",10);   
$Test->drawTitle(60,22,"Per Hour Hits",50,50,50,585); 
$img_filename = 'resource/chart/hitsperhour.png';
$Test->Render($img_filename);
echo '<table><tr><th>时段点击</th></tr> <tr><td style="background:#ffffff;text-align:left;"><img src="'.$img_filename.'"></td></tr></table>';
?>

<?php
$data = array();
$label = array();
foreach ($res_day_hits_60 as $row) {
	$data[] = $row['hits'];
	$label[] = date('j', strtotime($row['date']));
	// $data[$row['date']] = $row['hits'];
}

$data = array_reverse($data);
$label = array_reverse($label);

// (1)数据  
$DataSet = new pData();
$DataSet->AddPoint($data, "Serie1");
//$DataSet->AddPoint($hour_data_final2, "Serie2");
$DataSet->AddPoint($label, "Serie3");
$DataSet->AddSerie('Serie1');  
//$DataSet->AddSerie('Serie2');  
$DataSet->SetAbsciseLabelSerie("Serie3");
$DataSet->SetSerieName("60 Days", "Serie1");   
//$DataSet->SetSerieName("Today","Serie2");   
$DataSet->SetYAxisName("Hits");
$DataSet->SetXAxisName("Hour");

// (2)图表
$Test = new pChart(1000,255);
$Test->setFontProperties("resource/fonts/tahoma.ttf",8);   
$Test->setGraphArea(70,30,980,210); 
$Test->drawFilledRoundedRectangle(7,7,993,248,5,240,240,240);   
$Test->drawRoundedRectangle(5,5,695,250,5,230,230,230); 
$Test->drawGraphArea(255,255,255,TRUE);
$Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,2);   
$Test->drawGrid(4,TRUE,230,230,230,50);
// Draw the 0 line
$Test->setFontProperties("resource/fonts/tahoma.ttf",6);   
$Test->drawTreshold(0,143,55,72,TRUE,TRUE);
// Draw the line graph
$Test->drawLineGraph($DataSet->GetData(),$DataSet->GetDataDescription());   
$Test->drawPlotGraph($DataSet->GetData(),$DataSet->GetDataDescription(),3,2,255,255,255);

// (3)显示
$Test->setFontProperties("resource/fonts/tahoma.ttf",8);   
$Test->drawLegend(75,35,$DataSet->GetDataDescription(),255,255,255);   
$Test->setFontProperties("resource/fonts/tahoma.ttf",10);   
$Test->drawTitle(60,22,"Daily Hits",50,50,50,785); 
$img_filename = 'resource/chart/hitsdate.png';
$Test->Render($img_filename);
echo '<table><tr><th>每日点击图</th></tr> <tr><td style="background:#ffffff;text-align:left;"><img src="'.$img_filename.'"></td></tr></table>';
?>

<?php require VIEW_ROOT.'/common/footer.php'?>
